package translinkApp.Adaptors;

import java.util.ArrayList;

import translinkApp.Activities.R;
import translinkApp.Data.GoCard.GoCardTransaction;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class GoCardTransactionArrayAdapter extends ArrayAdapter {

	private Context context;

	public GoCardTransactionArrayAdapter(Context context, ArrayList<GoCardTransaction> list) {
		super(context, R.layout.historylistitem, list);

		this.context = context;
	}

	@Override
	public boolean areAllItemsEnabled() {
		return false;
	}

	@Override
	public boolean isEnabled(int position) {
		return false;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		GoCardTransaction c = (GoCardTransaction) getItem(position);

		// if the array item is null, nothing to display, just return null
		if (c == null) {
			return null;
		}

		// Pick up the TwoLineListItem defined in the xml file
		View view = View.inflate(context, R.layout.gocardhistorylistitem, null);

		TextView dateText = (TextView) view.findViewById(R.id.gocardHistoryDate);
		dateText.setText(c.getDate());

		TextView actionText = (TextView) view.findViewById(R.id.gocardHistoryAction);
		String actionString = c.getAction();
		if (!c.getAmount().equals("")) {
			actionString += " (" + c.getAmount() + ")";
		}
		actionText.setText(actionString);

		TextView locationText = (TextView) view.findViewById(R.id.gocardHistoryLocation);
		locationText.setText(c.getLocation());

		return view;
	}

}